$(function () {
    let form = layui.form
    form.verify({
        nickname: [
            /^[\S]{1,10}$/,
            '昵称的长度为1-10个字符!'
        ]
    })
    initUserInfo();
    let layer = layui.layer
    function initUserInfo() {
        axios({
            url:'/my/userinfo',
            method:'get',
  
        }).then(res=>{
            //成功回调
            // console.log(res)
            if (res.data.status !== 0) {
                return layer.msg(res.data.message)
            }
            form.val("formUserInfo",res.data.data);
        });
    } 
    $('#btnReset').on('click', function (e) {
        e.preventDefault()
        initUserInfo()
    })
    $('form').on('submit', function (e) {
        e.preventDefault()
        axios({
            url:'/my/userinfo',
            method:'post',
            data: $(this).serialize()
        }).then(res=>{
            //成功回调
            if (res.data.status != 0) {
                return layer.msg(res.data.message)
            }
            layer.msg('恭喜你修改成功')
            window.parent.getUserInfo()
        });
    })
})